package com.yulang.product_server.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

@Configuration
public class TockenConfig {

    @Bean
    public JwtAccessTokenConverter jwtAccessTokenConverter(){
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();

        converter.setVerifierKey("-----BEGIN PUBLIC KEY-----\n" +
                "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAvawoEejmTCWrU/WeSmbc\n" +
                "fPOwnqjpG7LTbPw8E602wpscgP0DYHra1sfMs1Ou7IZ2sZHZCN7UrEXu+4y3Rj0S\n" +
                "3KZLGI0ChhMcTfdgC1nwKtXICutdO6EdKjrcME8yOrPTWfUp+UXedrAnomcjrx54\n" +
                "X4+/E3iGCgoLfwMgRAwCiD//1IiEHKpG1IHjShy+WcR8YbAOnZbbMDF3GIDKK3Ki\n" +
                "cETErXGvgdVnGoIH2vvn0QBvGbkobU4tdaKnCH/LP1zsrepjRmP0pyaFCuxbP4Oj\n" +
                "aclD6uqkzaWtkq5XES5SzTSy9zqHcrCvqJBwkJLa7oYwCPHy3KM5OB9JdG94yi0E\n" +
                "JwIDAQAB\n" +
                "-----END PUBLIC KEY-----");
        return converter;
    }

    @Bean
    public TokenStore tokenStore(){
        //return new RedisTokenStore(redisConnectionFactory);
        //return new JdbcTokenStore(dataSource());
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

}
